package com.lintrip.future;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FutureData implements Data {

    private static final Logger logger = LoggerFactory.getLogger(FutureData.class);

    private RealData realData = null;
    private boolean ready = false;

    public synchronized void setRealData(RealData realData) {
        if (ready) {
            return;
        }
        this.realData = realData;
        this.ready = true;
        notifyAll();
    }

    @Override
    public synchronized String getContent(){
        while (!ready) {
            try {
                wait();
            } catch (InterruptedException e) {
                logger.error("Get Content occur exception",e);
            }
        }
        return realData.getContent();
    }
}
